from django.shortcuts import render

# Create your views here.
from rest_framework.generics import ListAPIView
from course.models import CourseCategory,Course,CourseChapter
from luffyapi.apps.course.serializers import CourseCategoryModelSerializer,CourseModelSerializer,CourseChapterSerializer


# 获取课程分类
class CourseCategoryListAPIView(ListAPIView):
    queryset = CourseCategory.objects.filter(is_show=True,is_deleted=False).order_by("orders")
    serializer_class = CourseCategoryModelSerializer



# 获取课程详情信息
# class CourseListAPIView(ListAPIView):
#     queryset = Course.objects.filter(is_deleted=False, is_show=True).order_by("orders")
#     serializer_class = CourseModelSerializer


from django_filters import rest_framework as f
from rest_framework.filters import OrderingFilter
from .paginations import CustomPageNumberPagination
class CourseListAPIView(ListAPIView):
    queryset = Course.objects.filter(is_deleted=False, is_show=True).order_by("orders","-id")
    serializer_class = CourseModelSerializer
    filter_backends = [f.DjangoFilterBackend,OrderingFilter]
    # 过滤的字段
    filterset_fields = ('course_category',)
    # 筛选的字段
    ordering_fields = ('id','students','price')
    # 指定分页器
    pagination_class = CustomPageNumberPagination


from rest_framework.generics import RetrieveAPIView
from .serializers import CourseRetrieveSerializer
class CourseRetrieveAPIView(RetrieveAPIView):
    queryset = Course.objects.filter(is_deleted=False, is_show=True)
    serializer_class = CourseRetrieveSerializer




class CourseChapterListAPIView(ListAPIView):
    queryset = CourseChapter.objects.filter(is_deleted=False, is_show=True).order_by("chapter")
    serializer_class = CourseChapterSerializer
    filter_backends = [f.DjangoFilterBackend]
    filter_fields = ['course', ]






